package cn.stylefeng.guns.modular.order.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.order.entity.WhOutOrderAllocate;
import cn.stylefeng.guns.modular.order.mapper.WhOutOrderAllocateMapper;
import cn.stylefeng.guns.modular.order.model.params.WhOutOrderAllocateParam;
import cn.stylefeng.guns.modular.order.model.result.WhOutOrderAllocateResult;
import  cn.stylefeng.guns.modular.order.service.WhOutOrderAllocateService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 武汉合单商品分配 服务实现类
 * </p>
 *
 * @author wp
 * @since 2025-10-13
 */
@Service
public class WhOutOrderAllocateServiceImpl extends ServiceImpl<WhOutOrderAllocateMapper, WhOutOrderAllocate> implements WhOutOrderAllocateService {

    @Override
    public void add(WhOutOrderAllocateParam param){
        WhOutOrderAllocate entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(WhOutOrderAllocateParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(WhOutOrderAllocateParam param){
        WhOutOrderAllocate oldEntity = getOldEntity(param);
        WhOutOrderAllocate newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public WhOutOrderAllocateResult findBySpec(WhOutOrderAllocateParam param){
        return null;
    }

    @Override
    public List<WhOutOrderAllocateResult> findListBySpec(WhOutOrderAllocateParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(WhOutOrderAllocateParam param,String condition){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public  List<WhOutOrderAllocateResult> getOutOrderAllocate(String storageOutNumber, Long storageGoodsId) {
        return this.baseMapper.getOutOrderAllocate(storageOutNumber, storageGoodsId);
    }

    @Override
    public WhOutOrderAllocateResult getOutOrderAllocateUn(String storageOutNumber, Long storageGoodsId) {
        return this.baseMapper.getOutOrderAllocateUn(storageOutNumber, storageGoodsId);
    }

    @Override
    public List<WhOutOrderAllocateResult> getOutOrderAllocateDetail(String storageOutNumber, Long storageGoodsId) {
        return this.baseMapper.getOutOrderAllocateDetail(storageOutNumber, storageGoodsId);
    }

    private Serializable getKey(WhOutOrderAllocateParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private WhOutOrderAllocate getOldEntity(WhOutOrderAllocateParam param) {
        return this.getById(getKey(param));
    }

    private WhOutOrderAllocate getEntity(WhOutOrderAllocateParam param) {
        WhOutOrderAllocate entity = new WhOutOrderAllocate();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
